package com.example.servlet;

import com.example.bean.Student;
import com.example.dao.StudentUpdateDao;
import com.example.dao.StudentUpdateDaoImp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "UpdateServlet", value = "/update")
public class UpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取浏览器发来的信息
        response.setContentType("html/text;charset=utf-8");
        response.sendRedirect("updateTarget.jsp");

        String sname = request.getParameter("sname");
        System.out.println("该学员的姓名为:"+sname);
        String ssex = request.getParameter("ssex");
        System.out.println("修改后的性别为:"+ssex);
        String sage = request.getParameter("sage");
        System.out.println("修改后的出生日期为:"+sage);
        String semail = request.getParameter("semail");
        System.out.println("修改后的邮箱为:"+semail);
        String stext = request.getParameter("stext");
        System.out.println("修改后的备注为:"+stext);

        //2.将数据交给Dao层进行处理
        Student student=new Student(sname,ssex,sage,semail,stext);
        StudentUpdateDao studentUpdateDao=new StudentUpdateDaoImp();
        studentUpdateDao.getStudentUpdate(student);

        request.getSession().setAttribute("success","修改成功!");
    }
}
